<template>
  <div class="digitalAssets">
    <div class="orderBox">
      <x-header :left-options="{backText: ''}">数字资产</x-header>
      <div style=" position: absolute;right: 15px;top: 8px;z-index:10">
        <span style="color: #fff;font-size: 17px;" @click="$router.push({path:'/main/typeOrder'})">已赎回</span>
      </div>
    </div>
    <div style="position: absolute;top: 60px;margin-left: 10px;overflow-x: scroll;-webkit-overflow-scrolling: touch;-webkit-overflow-scrolling : touch;width: 97%;"
      id="box" @scroll="myscroll()">
      <ul style="overflow-x: scroll;-webkit-overflow-scrolling: touch;-webkit-overflow-scrolling : touch; " v-if="allData&&allData.length==1">
        <li class="typeList" v-for="(order,index) in allData" :class="{ethBg:order.type=='eth',btcBg:order.type=='btc',bncnBg:order.type=='bncn'}"
          style="width: 98%">
          <div style="position: absolute;top: 0px;width: 92%;text-align: center;margin-left: 20px;border-bottom: 1px dashed #fff;color: #fff; height: 90px;padding-top: 5px;height: 150px;">
            <div>总计</div>
            <div style="font-size: 20px;">{{order.total||0}}{{order.type|upperCase}}</div>
            <div class="fr" style="height: 30px;border-bottom: 1px dashed #fff;">
              <span class="lineIcon"></span>
              <span class="fa l10">{{order.type|upperCase}}余额</span>
              <span class="fa r0">{{order.mount||0}}</span>
            </div>
          </div>
          <div class="typeBtn">
            <span @click="transferIn(order)" :class="{ethColor:order.type=='eth',btc:order.type=='btc',bncnColor:order.type=='bncn'}">转入</span>
            <span @click="transferOut(order.type)">转出</span>
          </div>
        </li>
        <div style="clear: both;"></div>
      </ul>
      <ul style="overflow-x: scroll;-webkit-overflow-scrolling: touch;-webkit-overflow-scrolling : touch; " :style="{width:315*allData.length+'px'}"
        v-if="allData&&allData.length>1">
        <li class="typeList" v-for="(order,index) in allData" :class="{ethBg:order.type=='eth',btcBg:order.type=='btc',bncnBg:order.type=='bncn'}">
          <div style="position: absolute;top: 0px;width: 260px;text-align: center;margin-left: 20px;border-bottom: 1px dashed #fff;color: #fff; height: 90px;padding-top: 5px;height: 150px;">
            <div>总计</div>
            <div style="font-size: 20px;">{{order.total||0}}{{order.type|upperCase}}</div>
            <div class="fr" style="height: 30px;border-bottom: 1px dashed #fff;">
              <span class="lineIcon"></span>
              <span class="fa l10">{{order.type|upperCase}}余额</span>
              <span class="fa r0">{{order.mount||0}}</span>
            </div>
          </div>
          <div class="typeBtn">
            <span @click="transferIn(order)" :class="{ethColor:order.type=='eth',btc:order.type=='btc',bncnColor:order.type=='bncn'}">转入</span>
            <span @click="transferOut(order.type)">转出</span>
          </div>
        </li>
        <div style="clear: both;"></div>
      </ul>
    </div>
    <div class="orderList" style="background: #f6f6f6;min-height: 585px;">
      <div style="height: 40px;background: #f6f6f6;"></div>
      <div class="orderDetail">
        <div class="orderGoods" v-for="goods in orderList">
          <div class="orderGoods-top fr">
            <img src="../../assets/order.png" alt="" width="30" style="margin-top:10px;">
            <div class="fa" style="top: 10px;left: 50px;">
              <span style="display: block;" class="fontSize14">{{goods.name}}</span>
              <span class="c9 fontSize11">订单号:{{goods.orderid}}</span>
            </div>
            <span class="fa r15 t10 ff10" :class="{green:goods.status=='已赎回'||goods.status=='已付款'}">{{goods.status}}</span>
          </div>
          <div style="position: relative;padding-bottom: 5px;">
            <div class="orderGoods-center" v-for="everyGoogs in goods.rate">
              <div class="c6">
                {{everyGoogs.key}}:
                <span class="ff10">{{everyGoogs.val}}</span>
              </div>
            </div>
            <div class="orderGoods-center">
              <div class="c6" style="color: #999;">
                购买时间:{{goods.created.split(" ")[0]}}
              </div>
              <div class="c6" style="color: #999;">
                到期时间:{{goods.open}}
              </div>
            </div>
            <div style="position: absolute;right: 15px;bottom: 13px;" v-if="goods.payAmount">
              <span>本金</span>
              <span style="color: #ff1010">{{goods.payAmount}}</span>
            </div>
          </div>
          <div class="orderGoods-bottom fr" v-if="goods.btn&&goods.btn.length>0">
            <div class="fa r15">
              <span v-for="btn in goods.btn" class="span" :class="{pay:btn==1||btn==6,mgr7:goods.btn.length>1}">
                <span v-if="btn==1" @click="applyPay(goods.orderid)">继续支付</span>
                <span v-if="btn==2" @click="cancelBtn(goods.orderid)">取消订单</span>
                <span v-if="btn==3" @click="registerList(goods.orderid)">我要挂单</span>
                <span v-if="btn==4" @click="registerList(goods.orderid)">修改挂单</span>
                <span v-if="btn==5" @click="revokeOrder(item.orderid)">撤销挂单</span>
                <span v-if="btn==6" @click="continueInvest(goods.orderid)">续资</span>
                <span v-if="btn==7" @click="applyRedemption(goods.orderid)">申请赎回</span>
              </span>
            </div>
          </div>
        </div>
        <div style="text-align: center;" v-if="orderList&&orderList.length==0">
          <img src="../../assets/kong.png" alt="" width="120">
        </div>
      </div>
    </div>

    <!-- 输入支付密码 -->
    <div class="tips" v-show="showTips">
      <div class="tips-top">
        <div style="text-align: center;height: 45px;line-height: 45px;border-bottom: 1px solid #f6f6f6;">
          <img src="../../assets/close.png" alt="" width="20" @click="showTips=false">
          <span class="c3">请输入支付密码</span>
        </div>
        <div>
          <div class="tips-center">
            <li>
              <input type="password" v-model="pwd1" maxlength="1" @keyup="pay()" class="input">
            </li>
            <li>
              <input type="password" v-model="pwd2" maxlength="1" @keyup="pay()" class="input">
            </li>
            <li>
              <input type="password" v-model="pwd3" maxlength="1" @keyup="pay()" class="input">
            </li>
            <li>
              <input type="password" v-model="pwd4" maxlength="1" @keyup="pay()" class="input">
            </li>
            <li>
              <input type="password" v-model="pwd5" maxlength="1" @keyup="pay()" class="input">
            </li>
            <li>
              <input type="password" v-model="pwd6" maxlength="1" @keyup="pay()" class="input">
            </li>
          </div>
          <div class="forgetPassWord" @click="$router.push({path:'/main/forgetPay'})">忘记密码?</div>
        </div>
      </div>
    </div>
    <!-- 支付密码错误弹框 -->
    <div class="errTips" v-if="errTips">
      <div class="errTipsBox">
        <div class="errTips-top">
          支付密码错误,请重试!
        </div>
        <div class="errTipsBtn">
          <span class="active" @click="retry">重试</span>
          <span @click="$router.push({path:'/main/forgetPay'})">忘记密码?</span>
        </div>
        <div style="margin-left: 30px;font-size: 13px;margin-top: 5px;color: #ff1010">(说明：只能重试3次)</div>
      </div>
    </div>
    <!-- 设置支付密码 -->
    <div class="setPassWorldTips" v-if="isPassWorld" @click="isPassWorld=false">
      <div class="setPasswordText">
        <div class="setPassWorldTitle">请设置支付密码!</div>
        <div class="goPassworld" @click="$router.push({path:'/main/setPayPassword'})">立即前往</div>
      </div>
    </div>
    <!-- 挂单弹框 -->
    <div v-transfer-dom>
      <confirm v-model="show5" show-input ref="confirm5" :title="'请输入挂单金额'" @on-confirm="isTrue">
      </confirm>
    </div>
  </div>
</template>
<script>
  import { XHeader } from 'vux'
  import axios from 'axios'
  import http from '../../service/http.js'
  import tips from '../../service/tips.js'
  import util from '../../service/util.js'
  import { Confirm, Group, XSwitch, XButton, TransferDomDirective as TransferDom } from 'vux'
  export default {
    directives: {
      TransferDom
    },
    components: {
      XHeader,
      Confirm,
      Group,
      XSwitch,
      XButton
    },
    data() {
      return {
        showTips: false,//显示支付密码弹框
        errTips: false,//显示支付错误弹框
        isPassWorld: false,//判断有没有支付密码
        status: 5,//全部
        order: [],
        pwd: "",
        pwd1: "",
        pwd2: "",
        pwd3: "",
        pwd4: "",
        pwd5: "",
        pwd6: "",
        allData: [],
        orderList: [],
        key: '',
        show5: false,
        gdMoney: '',
        gdId: "",
        scrollNum: 0,
        scrollArr: []
      }
    },
    filters: {
      upperCase: function (myInput) {
        return myInput.toUpperCase();
      }
    },
    mounted() {
      this.getAll();
    },
    methods: {
      myscroll() {
        var box = document.getElementById("box").scrollLeft;
        this.scrollNum = Math.floor(box / 270);
        this.orderList = this.allData[this.scrollNum].lists;
      },
      // 挂单
      isTrue(value) {
        this.gdMoney = value
        this.show5 = false;
        http.post("/order/putOrder", {
          orderid: this.gdId,
          putAmount: this.gdMoney
        }).then((res) => {
          if (res.status == 200) {
            tips.tips(res.data.msg);
          } else {
            tips.tips(res.data.msg)
          }
        }).catch((res) => {
          tips.tips(res.data.msg)
        })
      },
      transferIn(order) {
        // this.$router.push({ path: '/main/rechargeCardCurr?type=' + order.type })
        this.$router.push({ path: '/main/turnIn?type=' + order.type })
      },
      transferOut(type) {
        this.$router.push({ path: '/main/transferOut?type=' + type })
      },
      setType(key) {
        this.orderList = this.allData[key].lists;
      },
      getAll(key) {
        http.get('/order/orderList?type=DIG').then((res) => {
          if (res.status == 200) {
            this.key = key || res.data.body[0].type
            this.allData = res.data.body; //这里作为总的数据容器
            this.orderList = this.allData[0].lists;//这里为渲染的数据
            // res.data.body.forEach((v) => {
            //  this.scrollArr.push(v.type);
            //   if (v.type == this.key) {
            //     this.orderList = v.lists
            //   }
            // })
          }
        })
      },
      pay() {
        if (this.pwd1 && this.pwd2 && this.pwd3 && this.pwd4 && this.pwd5 && this.pwd6) {
          this.pwd = util.md5(this.pwd1 + this.pwd2 + this.pwd3 + this.pwd4 + this.pwd5 + this.pwd);
          http.post("/user/authPay", {
            payPwd: this.pwd
          }).then((res) => {
            if (res.data.status == 200) {
              // 密码成功之后进行下单;
              this.payOrder()
            } else {
              this.showTips = false;
              this.errTips = false;
              this.isPassWorld = false;
              tips.tips(res.data.msg);
              this.pwd1 = "";
              this.pwd2 = "";
              this.pwd3 = "";
              this.pwd4 = "";
              this.pwd5 = "";
              this.pwd6 = "";
            }
          })
        }
      },
      continueInvest(id) {
        http.post("/order/goOrder", {
          orderid: id
        }).then((res) => {
          if (res.status == 200) {
            tips.tips(res.data.msg)
          } else {
            tips.tips(res.data.msg)
          }
        }).catch((res) => {
          tips.tips(res.data.msg)
        })
      },
      // 取消
      cancelBtn(id) {
        tips.tips("30分钟后会自动取消订单")
      },
      // 继续支付
      applyPay(id) {
        this.id = id;
        //判断是否有支付密码
        http.post('/user/hasPay', {
          username: window.localStorage.getItem("login.username")
        }).then((res) => {
          if (res.status == 200 && res.data.body) {
            this.showTips = true;
          } else if (res.status == 200 && !res.data.body) {
            this.isPassWorld = true;
          }
        })
      },
      checkPwd() {
        this.pwd = this.pwd1 + this.pwd2 + this.pwd3 + this.pwd4 + this.pwd5 + this.pwd6;
        if (this.pwd1 && this.pwd2 && this.pwd3 && this.pwd4 && this.pwd5 && this.pwd6) {
          http.post('/user/authPay', {
            payPwd: util.md5(this.pwd)
          }).then((resultData) => {
            if (resultData.status == 200 && resultData.data.body) {//支付密码正确 如果是余额支付 调用付款的接口
              if (this.radioFlags[0] || this.hbAmount) {
                this.payOrder()
              } else {
                this.showTips = false;
                this.errTips = false;
                this.isPassWorld = false;
                this.pwd1 = ""
                this.pwd2 = ""
                this.pwd3 = ""
                this.pwd4 = ""
                this.pwd5 = ""
                this.pwd6 = ""
                tips.tips('下单成功，请去银联官网支付');
              }
            } else {
              this.showTips = false;
              this.errTips = false;
              this.isPassWorld = false;
              this.pwd1 = ""
              this.pwd2 = ""
              this.pwd3 = ""
              this.pwd4 = ""
              this.pwd5 = ""
              this.pwd6 = ""
              tips.tips(resultData.data.msg);
            }
          }).catch((resultData) => {
            this.showTips = false;
            this.errTips = false;
            this.isPassWorld = false;
            this.pwd1 = ""
            this.pwd2 = ""
            this.pwd3 = ""
            this.pwd4 = ""
            this.pwd5 = ""
            this.pwd6 = ""
            tips.tips(resultData.data.msg);
          })
        }
      },
      // 支付
      payOrder() {
        http.post("/coins/pay", {
          orderid: this.orderid
        }).then((resPay) => {
          if (resPay.status == 200) {
            this.$router.push({ path: "successPay", query: { pid: this.id } })
          } else {
            this.showTips = false;
            this.errTips = false;
            this.isPassWorld = false;
            this.pwd1 = ""
            this.pwd2 = ""
            this.pwd3 = ""
            this.pwd4 = ""
            this.pwd5 = ""
            this.pwd6 = ""
            tips.tips(resPay.data.msg);
          }
        }).catch((resPay) => {
          this.showTips = false;
          this.errTips = false;
          this.isPassWorld = false;
          this.pwd1 = ""
          this.pwd2 = ""
          this.pwd3 = ""
          this.pwd4 = ""
          this.pwd5 = ""
          this.pwd6 = ""
          tips.tips(resPay.data.msg);
        })
      },
      // 赎回
      applyRedemption(id) {
        http.post('/order/backOrder', {
          orderid: id
        }).then((res) => {
          if (res.status == 200) {
            tips.tips(res.data.msg)
          } else {
            tips.tips(res.data.msg)
          }
        }).catch((res) => {
          tips.tips(res.data.msg)
        })
      },
      //取消挂单
      revokeOrder(id) {
        http.post("/order/cancelPut", {
          orderid: id
        }).then((res) => {
          if (res.data.status == 200) {
            tips.tips(res.data.msg);
            this.getOrder();
          } else {
            tips.tips(res.data.msg)
          }
        }).catch((res) => {
          tips.tips(res.data.msg)
        })
      },
      // 修改挂单 我要挂单
      registerList(id) {
        this.gdId = id;
        this.show5 = true;
      },
      setStatus5() {
        this.status = 5;
        var url = '/order/orderList'
        http.get(url).then((res) => {
          if (res.data.status == 200) {
            this.order = res.data.body;
          }
        })
      },
      setStatus(status) {
        this.status = status;
        this.getOrderList(status);
      },
      getOrderList(status) {
        var url = "/order/orderList?status=" + status
        http.get(url).then((res) => {
          if (res.data.status == 200) {
            this.order = res.data.body;
          }
        })
      }
    },
  }
</script>
<style lang="less">
  body {
    background: #f6f6f6;
  }

  .orderBox {
    height: 150px;
    background: url("../../assets/myBgColor.png")
  }

  .mgr7 {
    margin-right: 7px;
  }

  .l10 {
    left: 10px;
  }

  .r0 {
    right: 0px;
  }

  .digitalAssets .vux-header {
    padding: 3px 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0);
    width: 100%;
    z-index: 9;
  }

  .fr {
    position: relative;
  }

  .fontSize14 {
    font-size: 14px;
  }

  .fontSize11 {
    font-size: 11px;
  }

  .t0 {
    top: 0px;
  }

  .fa {
    position: absolute;
  }

  .c0 {
    color: #000;
  }

  .c3 {
    color: #333;
  }

  .c6 {
    color: #666;
  }

  .c9 {
    color: #999;
  }

  .ff10 {
    color: #ff1010;
  }

  .green7e {
    color: #7ed321;
  }

  .l15 {
    left: 15px;
  }

  .r15 {
    right: 15px;
  }

  .t10 {
    top: 10px;
  }

  .digitalAssets .vux-header .vux-header-left .left-arrow:before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid #fff;
    border-width: 1px 0 0 1px;
    -webkit-transform: rotate(315deg);
    transform: rotate(315deg);
    top: 8px;
    left: 7px;
  }

  .digitalAssets .vux-header .vux-header-title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 400;
    color: #fff;
  }

  .digitalAssets .select {
    color: #fea620;
    border-bottom: 1px solid #fea620;
  }

  .digitalAssets .orderList ul {
    /* padding-left: 10px; */
    /* padding-right: 10px; */
    background: #fff;
    margin-top: 45px;
    position: fixed;
    width: 100%;
    z-index: 999;
    border-top: 1px solid #f6f6f6;
  }

  .digitalAssets .orderList {
    border-top: 1px solid #f6f6f6;
  }

  .orderList ul {
    background: #fff;
  }

  .digitalAssets .orderList ul li {
    float: left;
    list-style: none;
    height: 40px;
    line-height: 40px;
    width: 20%;
    text-align: center;
  }

  .digitalAssets .orderDetail {
    padding: 10px;
  }

  .digitalAssets .orderGoods {
    background: #fff;
    border-radius: 15px;
    margin-bottom: 15px;
  }

  .digitalAssets .orderGoods-top {
    padding-left: 15px;
    height: 65px;
    border-bottom: 1px solid #f6f6f6;
  }

  .digitalAssets .orderGoods-center {
    padding-left: 50px;
    margin-top: 5px;
    margin-bottom: 5px;
    div {
      height: 30px;
      line-height: 30px;
    }
  }

  .digitalAssets .orderGoods-bottom {
    height: 65px;
    line-height: 65px;
    border-top: 1px solid #f6f6f6;
    .span {
      height: 25px;
      line-height: 25px;
      border-radius: 25px;
      display: inline-block;
      border: 1px solid #999;
      color: #999;
      width: 85px;
      text-align: center;
    }
  }

  .digitalAssets .orderGoods-bottom .pay {
    background: #fea620;
    color: #fff !important;
    border: 1px solid #fea620 !important;
  }

  .green {
    color: #88d731 !important;
  }

  .digitalAssets .payPassword {
    /* background: #000; */
    position: fixed;
    top: 0px;
    left: 0px;
    bottom: 0px;
    right: 0px;
    /* opacity: 0.3; */
    z-index: 9999;
    background: rgba(0, 0, 0, 0.3);
  }

  .digitalAssets .continuePay {
    position: fixed;
    top: 40%;
    bottom: 0px;
    left: 0px;
    right: 0px;
    background: #fff;
  }

  .digitalAssets .tips {
    position: fixed;
    background: rgba(0, 0, 0, 0.3);
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    z-index: 999;
    .tips-top {
      position: absolute;
      top: 40%;
      height: 60%;
      background: #fff;
      width: 100%;
      border-bottom: 1px solid #f6f6f6;
      img {
        position: absolute;
        left: 15px;
        top: 15px;
      }
    }
  }

  .tips-center {
    padding-left: 10%;
    margin-top: 45px;
  }

  .tips-center li {
    float: left;
    width: 15%;
    list-style: none;
    height: 45px;
    line-height: 45px;
    border: 1px solid #ccc;
    border-right: none;
    overflow: hidden;
    text-align: center;
    input {
      border: none;
      outline: none;
      height: 45px;
      line-height: 45px;
      width: 100%;
      display: block;
      text-align: center;
    }
  }

  .tips-center li:last-child {
    border-right: 1px solid #ccc;
  }

  .forgetPassWord {
    position: absolute;
    right: 28px;
    top: 150px;
    color: #fea620;
  }

  .errTips {
    position: fixed;
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
  }

  .errTipsBox {
    position: absolute;
    top: 40%;
    width: 90%;
    height: 130px;
    background: #fff;
    margin-left: 5%;
    border-radius: 15px;
    .errTips-top {
      height: 60px;
      line-height: 60px;
      text-align: center;
      border-bottom: 1px solid #efefef;
    }
    .errTipsBtn {
      span {
        display: inline-block;
        width: 48%;
        text-align: center;
        margin-top: 15px;
        color: #fea620;
      }
      .active {
        border-right: 1px solid #efefef;
      }
    }
  }

  .setPassWorldTips {
    position: fixed;
    top: 0px;
    left: 0px;
    bottom: 0px;
    right: 0px;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
  }

  .setPasswordText {
    position: absolute;
    top: 40%;
    height: 130px;
    background: #fff;
    width: 90%;
    margin-left: 5%;
    border-radius: 15px;
    .setPassWorldTitle {
      height: 60px;
      line-height: 60px;
      text-align: center;
      border-bottom: 1px solid #efefef;
      color: #000;
    }
    .goPassworld {
      height: 70px;
      line-height: 65px;
      color: #fea620;
      text-align: center;
    }
  }

  .typeList {
    list-style: none;
    float: left;
    margin-right: 15px;
    background: #7fd8dd;
    height: 150px;
    width: 300px;
    border-radius: 15px;
    position: relative;
  }

  .btcBg {
    background: #7fd8dd;
  }

  .btcColor {
    color: #7fd8dd !important;
  }

  .ethBg {
    background: #ffbcc2;
  }

  .ethColor {
    color: #ffbcc2 !important;
  }

  .bncnBg {
    background: #a08eff;
  }

  .bncnColor {
    color: #a08eff !important;
  }

  .typeBtn {
    position: absolute;
    bottom: 10px;
    right: 20px;
  }

  .typeBtn span:first-child {
    width: 75px;
    text-align: center;
    height: 30px;
    line-height: 30px;
    border-radius: 5px;
    background: #fff;
    display: inline-block;
    color: #7fd8dd;
    bottom: 10px;
    right: 20px;
  }

  .typeBtn span:last-child {
    width: 75px;
    text-align: center;
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    display: inline-block;
    bottom: 10px;
    right: 20px;
    color: #fff;
    border: 1px solid #fff;
  }

  .lineIcon {
    width: 3px;
    height: 20px;
    background: #fff;
    display: inline-block;
    position: absolute;
    left: 0px;
    top: 5px;
  }

  .maxWidthBox {
    width: 100% !important;
  }
</style>